//
//  AddDeviceS2InfoController.m
//  O2Cat
//
//  Created by xiabin on 15/12/17.
//  Copyright © 2015年 QiDao.Purifier. All rights reserved.
//

#import "AddDeviceS2InfoController.h"
#import "AddDeviceS3WifiController.h"
#import "RegisterViewController.h"
#import "HardwareService.h"

@interface AddDeviceS2InfoController ()

@property (nonatomic,strong) UIButton* yesBtn;
@property (nonatomic,strong) UIImageView* infoImage;
@property (nonatomic,strong) UILabel* infoLabel;

@end

@implementation AddDeviceS2InfoController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = QGPageBG;
    [self.view addSubview:self.infoLabel];
    [self.view addSubview:self.infoImage];
    [self.view addSubview:self.yesBtn];
    
    [self layoutSubViews];
    // Do any additional setup after loading the view.
}

- (void) viewWillAppear:(BOOL)animated {
    [self setupNavStyle];
}

- (void) viewDidAppear:(BOOL)animated {
    if (QGHardwareService.userid == 0) {
        RegisterViewController* pageAdd = [RegisterViewController new];
        [self.navigationController pushViewController:pageAdd animated:NO];
        [QGHardwareService setUserid:11];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void) setupNavStyle {
    UIView *statusBarView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_SIZE_WIDTH, 20)];
    statusBarView.backgroundColor=QGNavBG;
    [self.view addSubview:statusBarView];
    self.navigationController.navigationBar.backgroundColor = QGNavBG;
    self.navigationController.navigationBar.barTintColor = QGNavBG;
    self.navigationItem.title = @"连接奇道空气净化器";
    
    
    UIButton* backBtn = [Utils NavButtonStyleNormalBLeft:YES NormalImg:@"back" AndHightLight:@"back"];
    [backBtn addTarget:self action:@selector(popBack) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
}

-(void) popBack {
    [self.navigationController popViewControllerAnimated:YES];
}

-(void) onBtnYes {
    AddDeviceS3WifiController* step3 = [[AddDeviceS3WifiController alloc] init];
    [self.navigationController pushViewController:step3 animated:YES];
}

-(void) layoutSubViews {
    //顶部排布
    __weak __typeof(&*self)weakSelf = self;
    
    [self.infoImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.view.mas_top).offset(SCREEN_SIZE_HEIGHT/4);
        make.centerX.mas_equalTo(weakSelf.view.mas_centerX).offset(0);
        make.height.mas_equalTo(SCREEN_SIZE_WIDTH/3);
        make.width.mas_equalTo(SCREEN_SIZE_WIDTH/3);
    }];
    
    [self.infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.infoImage.mas_bottom).offset(20);
        make.centerX.mas_equalTo(weakSelf.infoImage.mas_centerX).offset(0);
        //make.height.mas_equalTo(SCREEN_SIZE_WIDTH/3);
        //make.width.mas_equalTo(SCREEN_SIZE_WIDTH/3);
    }];
    
    [self.yesBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(weakSelf.view.mas_bottom).offset(-200);
        make.centerX.mas_equalTo(weakSelf.view.mas_centerX).offset(0);
        make.width.mas_equalTo(weakSelf.view.mas_width).offset(-60);
        make.height.mas_equalTo(50);
    }];
}

-(UIButton*) yesBtn {
    if (_yesBtn == nil) {
        _yesBtn = [[UIButton alloc] init];
        _yesBtn.backgroundColor = QGNavBG;
        _yesBtn.layer.cornerRadius = 4;
        [_yesBtn setTitle:@"是" forState:UIControlStateNormal];
        [_yesBtn setTitleColor:QGTextWhite forState:UIControlStateNormal];
        [_yesBtn setTitleColor:QGTextGrayL1 forState:UIControlStateHighlighted];
        [_yesBtn addTarget:self action:@selector(onBtnYes) forControlEvents:UIControlEventTouchUpInside];
    }
    return _yesBtn;
}


-(UIImageView*) infoImage {
    if (_infoImage == nil) {
        _infoImage = [[UIImageView alloc] init];
        _infoImage.image = [UIImage imageNamed:@"greenlight"];
        _infoImage.backgroundColor = QGTextGrayL2;
    }
    return _infoImage;
}

-(UILabel*) infoLabel {
    if (_infoLabel == nil) {
        _infoLabel = [[UILabel alloc] init];
        _infoLabel.text = @"请检查绿色指示灯是否闪烁";
        _infoLabel.textColor = QGTextGrayL1;
        _infoLabel.font = [UIFont systemFontOfSize:[Utils phoneFontL3]];
        [_infoLabel sizeToFit];
    }
    return _infoLabel;
}

@end